package Controller;

import Model.Emp;
import Service.serviceImpl.EmpService;

import java.io.IOError;
import java.util.Scanner;

public class UserController {
    public static int num;
    private static Integer empId = 1;

    public void userServiceResquest() {

        EmpService empService = new EmpService();
        Emp[] emp = new Emp[100];
        boolean flag = true;
        while (flag) {
            System.out.println("--------请选择你要操作的业务--------");
            System.out.println("1.查询员工信息");
            System.out.println("2.增加员工信息");
            System.out.println("3.删除员工信息");
            System.out.println("4.修改员工信息");
            System.out.println("5.退出");
            Scanner scanner = new Scanner(System.in);
            int menu = scanner.nextInt();
            switch (menu) {
                case 1:
                    // System.out.println("请输入要查询的员工id");
                    empService.showEmp(emp, UserController.num);
                    break;
                case 2:
                    //业务
                    //生成一条员工信息
                    Emp user = new Emp();
                    user.setEmpId(UserController.empId++);

                    System.out.println("请输入员工的姓名");
                    String name = scanner.next();
                    user.setName(name);

                    System.out.println("请输入员工的性别");
                    String sex = scanner.next();
                    user.setSex(sex);

                    System.out.println("请输入员工的年龄");
                    Integer age = scanner.nextInt();
                    user.setAge(age);

                    System.out.println("请输入员工的工作");
                    String job = scanner.next();
                    user.setJob(job);
                    //System.out.println("UserController.num = " + UserController.num);
                    empService.addEmp(emp, user, UserController.num);

                    break;
                case 3:
                    System.out.println("请输入你要删除的工号");
                    String empId = scanner.next();
                    empService.delEmp(emp, empId, UserController.num);
                    break;
                case 4:
                    System.out.println("请输入要修改的员工编号");
                    String empId1 = scanner.next();
                    boolean b=empService.updateEmp(emp, empId1, UserController.num);
                    String info=b?"更新成功":"没找到";
                    System.out.println("info="+info);
                    break;
                case 5:
                    System.out.println("4.再见");
                    flag = false;
                    break;
            }

        }
    }
}
